{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "\n",
    "def generate_data():\n",
    "    # 本函数生成0-9，10个数字的图片矩阵\n",
    "    image_data=[]\n",
    "    num_0 = torch.tensor(\n",
    "    [[0,0,1,1,0,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,0,1,1,0,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_0)\n",
    "    num_1 = torch.tensor(\n",
    "    [[0,0,0,1,0,0],\n",
    "    [0,0,1,1,0,0],\n",
    "    [0,0,0,1,0,0],\n",
    "    [0,0,0,1,0,0],\n",
    "    [0,0,1,1,1,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_1)\n",
    "    num_2 = torch.tensor(\n",
    "    [[0,0,1,1,0,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,0,0,1,0,0],\n",
    "    [0,0,1,0,0,0],\n",
    "    [0,1,1,1,1,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_2)\n",
    "    num_3 = torch.tensor(\n",
    "    [[0,0,1,1,0,0],\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,0,1,1,0,0],\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,0,1,1,0,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_3)\n",
    "    num_4 = torch.tensor(\n",
    "    [\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,0,0,1,1,0],\n",
    "    [0,0,1,0,1,0],\n",
    "    [0,1,1,1,1,1],\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_4)\n",
    "    num_5 = torch.tensor(\n",
    "    [\n",
    "    [0,1,1,1,0,0],\n",
    "    [0,1,0,0,0,0],\n",
    "    [0,1,1,1,0,0],\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,1,1,1,0,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_5)\n",
    "    num_6 = torch.tensor(\n",
    "    [[0,0,1,1,0,0],\n",
    "    [0,1,0,0,0,0],\n",
    "    [0,1,1,1,0,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,0,1,1,0,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_6)\n",
    "    num_7 = torch.tensor(\n",
    "    [\n",
    "    [0,1,1,1,1,0],\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,0,0,1,0,0],\n",
    "    [0,0,0,1,0,0],\n",
    "    [0,0,0,1,0,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_7)\n",
    "    num_8 = torch.tensor(\n",
    "    [[0,0,1,1,0,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,0,1,1,0,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,0,1,1,0,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_8)\n",
    "    num_9 = torch.tensor(\n",
    "    [[0,0,1,1,1,0],\n",
    "    [0,1,0,0,1,0],\n",
    "    [0,0,1,1,1,0],\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,0,0,0,1,0],\n",
    "    [0,0,0,0,0,0]])\n",
    "    image_data.append(num_9)\n",
    "    return image_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "image_data = generate_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[0, 0, 1, 1, 0, 0],\n",
      "        [0, 1, 0, 0, 1, 0],\n",
      "        [0, 1, 0, 0, 1, 0],\n",
      "        [0, 1, 0, 0, 1, 0],\n",
      "        [0, 0, 1, 1, 0, 0],\n",
      "        [0, 0, 0, 0, 0, 0]])\n"
     ]
    }
   ],
   "source": [
    "print(image_data[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "i=0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD4CAYAAAA0L6C7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAJrUlEQVR4nO3dz4tdhR2G8fdtOiYaFSm1kmRC48IK\nIm0sQ7pQCk2xiT/QLhV0JcymQqQF0aX/gLjpZlBpi9YgqCDWNg01IgGNTuJoTaISRDFRSIuIpqUx\n0beLuSlTjZkzN+fMOX55PjA4k7ncvJg8OfeembnHSQSgjm/1PQBAu4gaKIaogWKIGiiGqIFivt3F\nnZ7jlVml1V3cdRk/+OG/+54waG+/fl7fEwbtP/qXPstxn+5znUS9Sqv1E/+8i7suY8eOub4nDNqW\ntRv7njBoe/K3r/0cD7+BYogaKIaogWKIGiiGqIFiiBoohqiBYogaKIaogWKIGiiGqIFiiBoohqiB\nYhpFbXur7bdsH7J9T9ejAIxv0ahtr5D0W0nXSbpC0q22r+h6GIDxNDlSb5J0KMk7ST6TtF3Szd3O\nAjCuJlGvk/T+go8Pj37t/9ietj1re/aEjre1D8AStXaiLMlMkqkkUxNa2dbdAliiJlEfkbR+wceT\no18DMEBNon5F0mW2L7V9jqRbJD3d7SwA41r0hQeTnLR9p6QdklZIejjJ/s6XARhLo1cTTfKspGc7\n3gKgBXxHGVAMUQPFEDVQDFED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a1Y8GeNZLWJNk3\nek32vZJ+2df/I8+/fvTqJMdsT0jaLWlbkpf62LNg168lTUm6MMmNfW4Z7XlX0lTXF5oc4pF6k6RD\nSd5J8pmk7ZJu7nPQ6BJDH/W5YaEkHybZN3r/U0kHJa3rcU+SHBt9ODF66/VoYXtS0g2SHuxzRx+G\nGPU6Se8v+PiwevwLO3S2N0i6StKennessD0n6aiknUl63SPpAUl3S/qi5x0LLXqhyTYMMWo0ZPt8\nSU9IuivJJ31uSfJ5ko2SJiVtst3b0xTbN0o6mmRvXxu+xjVJfizpOkm/Gj2ta90Qoz4iaf2CjydH\nv4YFRs9dn5D0aJIn+95zSpKPJe2StLXHGVdLumn0HHa7pM22H+lxj6Tlu9DkEKN+RdJlti+1fY6k\nWyQ93fOmQRmdmHpI0sEk9w9gz8W2Lxq9f67mT3K+2deeJPcmmUyyQfN/f55Lcltfe6TlvdDk4KJO\nclLSnZJ2aP4E0ONJ9ve5yfZjkl6UdLntw7bv6HOP5o9Et2v+CDQ3eru+xz1rJO2y/brm/1HemWQQ\nX0YakEsk7bb9mqSXJf2pqwtNDu5LWgDOzuCO1ADODlEDxRA1UAxRA8UQNVAMUQPFEDVQzH8BIkdI\nH7VAqH0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(image_data[i%10])\n",
    "plt.show()\n",
    "i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def get_feature(x):\n",
    "    return torch.sum(x,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "x = image_data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([0, 3, 2, 2, 3, 0])\n"
     ]
    }
   ],
   "source": [
    "print(torch.sum(x,0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([0, 0, 3, 3, 2, 0])\n"
     ]
    }
   ],
   "source": [
    "print(get_feature(image_data[3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "i=0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# cmap color map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD4CAYAAAA0L6C7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAJrUlEQVR4nO3dUWhe9RnH8d9vSUWpDi+mEpKyeiHe\neDHX0htlbEJHNot6qbBdCbmZEhlDdHde7HZ4XVyZQ2cRakG6MVdYmCto26S2s2lVijhMEYIUWXMl\ntY8XOYVsJO8575tzcv55+v1AMG/65uUhJ9+c97yv5/wdEQKQx3f6HgBAu4gaSIaogWSIGkiGqIFk\nxrt4UNu8pF5jz549fY9QtIWFhb5HKF5EeL2vu4u3tIi6Hm8lDmav+/uKNTaKmqffQDJEDSRD1EAy\nRA0kQ9RAMkQNJEPUQDJEDSRD1EAyRA0kQ9RAMkQNJEPUQDKNorY9bftj25dsv9D1UABGV3vqpe0x\nSZ9I2i9pSdJpSU9FxIUB38N5hTU49XIwTr2st5lTL/dJuhQRn0bE15IOS3q8zeEAtKdJ1JOSPl9z\ne6n62v+wPWN73vZ8W8MBGF5rlzOKiIOSDko8/Qb61GRPfVnSrjW3p6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7Y9iXbLxQwzyHby7aLuDSy7V2252xfsL1oe7bneW61fcr2uWqel/qc5wbbY7Y/sH2s71mk\n1YUmbX9o+2yXK9kUd0xte0zSJ5L2S1qSdFrSUxFxoceZfiRpRdKfIuKBvuZYM8+EpImIOFNdk31B\n0hN9/Yy8ev3onRGxYnuHpBOSZiPi/T7mWTPXryXtlfTdiDjQ5yzVPJ9J2tv1QpMl7qn3SboUEZ9G\nxNeSDkt6vM+BqiWGrvQ5w1oR8UVEnKk+vyrpoqTJHueJiFipbu6oPnrdW9iekvSopFf6nKMPJUY9\nKenzNbeX1OMvbOls75b0oKSTPc8xZvuspGVJxyOi13kkvSzpeUnXe55jrdqFJttQYtRoyPbtko5I\nei4i/tvnLBHxTUT8QNKUpH22eztMsX1A0nJELPQ1wwYejogfSvqZpF9Vh3WtKzHqy5J2rbk9VX0N\na1THrkckvR4Rb/U9zw0R8ZWkOUnTPY7xkKTHqmPYw5Iesf1aj/NI2rqFJkuM+rSk+2zfa/sWSU9K\nervnmYpSvTD1B0kXI+L3Bcxzl+07q89v0+qLnB/1NU9EvBgRUxGxW6u/P/+IiF/0NY+0tQtNFhd1\nRFyT9Iykd7T6AtCbEbHY50y235D0nqT7bS/ZfrrPebS6J/qlVvdAZ6uPn/c4z4SkOdv/1uof5eMR\nUcTbSAW5R9IJ2+cknZL0l64WmizuLS0Am1PcnhrA5hA1kAxRA8kQNZAMUQPJEDWQDFEDyXwLoZ+v\nkh1vP3wAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([0, 3, 2, 2, 3, 0])\n"
     ]
    }
   ],
   "source": [
    "plt.imshow(image_data[i%10],cmap='gray')\n",
    "plt.show()\n",
    "\n",
    "print(get_feature(image_data[i%10]))\n",
    "i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [],
   "source": [
    "def model(x,image_data):\n",
    "    y=-1\n",
    "    \n",
    "    for i in range(0,10):\n",
    "        diff_tmp = x-image_data[i]\n",
    "        #print(\"i=%s\"%(i))\n",
    "        #print(\"diff_tmp=%s\"%(diff_tmp))\n",
    "        #print(\"sum(diff_tmp)=%s\"%(torch.sum(torch.abs(diff_tmp))))\n",
    "        if torch.sum(torch.abs(diff_tmp))==0:\n",
    "            y=i\n",
    "            break\n",
    "    print(\"%s ----> %s\"%(x,y))\n",
    "    return y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[0, 0, 1, 1, 0, 0],\n",
      "        [0, 1, 0, 0, 1, 0],\n",
      "        [0, 0, 1, 1, 0, 0],\n",
      "        [0, 1, 0, 0, 1, 0],\n",
      "        [0, 0, 1, 1, 0, 0],\n",
      "        [0, 0, 0, 0, 0, 0]]) ----> 8\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model(image_data[8],image_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
